package com.wf.mock.app.mina.app.processor.impl;

import java.util.List;

import lombok.extern.log4j.Log4j;

import org.apache.mina.core.session.IoSession;

import com.wf.mock.app.mina.MessageIntentType;
import com.wf.mock.app.mina.app.processor.IMessageProcessor;
import com.wf.mock.app.mina.dto.ConfirmMsgDTO;
import com.wf.mock.app.mina.dto.ConfirmMsgDTO.ConfirmState;
import com.wf.mock.app.mina.dto.RawMessageDTO;
import com.wf.mock.app.mina.dto.SplitMsgPacketDTO;
import com.wf.mock.app.utils.MinaUtils;

@Log4j
public class APP2PortalMessageProcessorImpl implements IMessageProcessor {


	@Override
	public void process(RawMessageDTO msgDto, IoSession session) {

//		RetrySendMsgManager.INSTANCE.addEvent(msgDto);
		List<String> msgs = SplitMsgPacketDTO.generateMsgPacket(msgDto.toString());
		for (String string : msgs) {
			session.write(string);
		}
	}

	private String buildMinaConfirmMsg(String markId, String errorMsg, ConfirmState state) {
		ConfirmMsgDTO confirmMsgDTO = new ConfirmMsgDTO();
		confirmMsgDTO.setMarkId(markId);
		confirmMsgDTO.setState(state);
		confirmMsgDTO.setReason(errorMsg);

		return MinaUtils.wrapMsg4App(MessageIntentType.MINACONFIRM.getPreffix() + confirmMsgDTO);
	}

}
